package com.zhang.common.email;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class EmailUtil {
    @Autowired
    private JavaMailSender javaMailSender;
    private String from = "3318878270@qq.com";

    /**发送简单邮件
     * @param to 收件人
     * @param subject 标题
     * @param content 内容
     */
    public void sendMailByString(String to, String subject, String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject(subject);//标题
        message.setText(content);
        try {
            javaMailSender.send(message);
        } catch (Exception e) {
            log.error("发送邮件失败--》{}", e);
        }

    }

}
